package com.hngy.xpq.android_practice.ui.notifications;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.hngy.xpq.android_practice.R;
import com.hngy.xpq.android_practice.database.SQLiteWallet;
import com.hngy.xpq.android_practice.http.TcpClient;

public class WalletActivity extends AppCompatActivity {

    Button recharge,withdraw,query;
    TextView money;
    SQLiteWallet sqLiteWallet;
    SharedPreferences main,merchant;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wallet_money);

        recharge = findViewById(R.id.wallet_recharge);
        withdraw = findViewById(R.id.wallet_withdraw);
        query = findViewById(R.id.wallet_query);
        money = findViewById(R.id.money);

        main = super.getSharedPreferences("main",MODE_PRIVATE);
        merchant = super.getSharedPreferences("merchants",MODE_PRIVATE);

        sqLiteWallet = new SQLiteWallet(this);
        String a = null;
        if (main.getString("name","").equals("")){
            a = String.valueOf(sqLiteWallet.QueryWithMoney(merchant.getString("phone","")));
        } else {
            String information = "CX001//" + main.getString("name","");
            a = new TcpClient().Transits(information);
        }
        money.setText(a);

        recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {         //充值
                Intent intent = new Intent(WalletActivity.this,WalletRecharge.class);
                startActivity(intent);
                finish();
            }
        });

        query.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {       //零钱明细
                Intent intent = new Intent(WalletActivity.this, WalletQuery.class);
                startActivity(intent);
            }
        });
    }
}